package vip.xiaonuo.smzq.modular.lifecycle.service.entity.impl;

import  java.util.List;
import java.util.Map;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import vip.xiaonuo.smzq.modular.lifecycle.entity.KclWjglb;
import vip.xiaonuo.smzq.modular.lifecycle.mapper.entity.KclWjglbMapper;
import vip.xiaonuo.smzq.modular.lifecycle.service.entity.KclWjglbService;
import vip.xiaonuo.smzq.modular.lifecycle.service.module.CommonService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * <p>
 * 资料上传文件关联表 服务实现类
 * </p>
 *
 * @author 于彦飞
 * @since 2024-03-20
 */
@Service(value="lifeCycleKclWjglbService")
public class KclWjglbServiceImpl extends ServiceImpl<KclWjglbMapper, KclWjglb> implements KclWjglbService {
        @Autowired
        private KclWjglbMapper kclWjglbMapper;

        @Autowired
        CommonService commonService;

        @Override
        public List<KclWjglb>  queryKclWjglbList(KclWjglb kclWjglb){
            List<KclWjglb> list = new LambdaQueryChainWrapper<KclWjglb>(kclWjglbMapper).setEntity(kclWjglb).orderByDesc(KclWjglb::getScsj)
            .list();
//            DictConvertUtil.convertToDictionaryList(list,null);
            return list;
        }

        @Override
        public IPage<KclWjglb> queryKclWjglbListPage(KclWjglb kclWjglb){
            IPage<KclWjglb> iPage = new LambdaQueryChainWrapper<KclWjglb>(kclWjglbMapper).setEntity(kclWjglb)
            .page(new Page<>(1,10));

            List<KclWjglb> records = iPage.getRecords();
//            DictConvertUtil.convertToDictionaryList(records,null);
            iPage.setRecords(records);
            return iPage;
        }


    @Override
    @Transactional
    public boolean delKclWjglb(String id){
        KclWjglb kclWjglb = this.getById(id);
        /*if(FileUtil.exist(kclWjglb.getWjlj()) && FileUtil.isFile(kclWjglb.getWjlj())){
            FileUtil.del(kclWjglb.getWjlj());
        }*/
        commonService.delFile(kclWjglb.getWjlj());
        return this.removeById(id);
    }
    @Override
    public boolean delKclWjglbBatch(List<String> ids){
        return this.removeByIds(ids);
    }

}

